import java.io.File;
import java.util.ArrayList;
import java.util.List;

import org.epiphron.EpiphronException;
import org.epiphron.SemanticValidator;
import org.epiphron.ValidityReport;
import org.epiphron.convert.RdfProperty;
import org.epiphron.pellet.PelletSemanticValidator;
import org.semanticweb.owlapi.apibinding.OWLManager;
import org.semanticweb.owlapi.model.OWLOntology;
import org.semanticweb.owlapi.model.OWLOntologyCreationException;

public class Car {
	String vin;
	
	@RdfProperty("slowerThan")
	List<Car> fasterCars = new ArrayList<Car>();
	
	@RdfProperty("fasterThan")
	List<Car> slowerCars = new ArrayList<Car>();
	
	public Car(String _vin) {
		vin = _vin;
	}
	
	public String getVin() {
		return vin;
	}
	
	public List<Car> getFasterCars() {
		return fasterCars;
	}
	
	public List<Car> getSlowerCars() {
		return slowerCars;
	}
	
	public static void main(String[] args) throws OWLOntologyCreationException, EpiphronException {
		OWLOntology ontology = 
			OWLManager.createOWLOntologyManager().loadOntologyFromOntologyDocument(new File("cars.owl"));
		
		SemanticValidator validator = new PelletSemanticValidator(); // use e.g. HermiTSemanticValidator for HermiT

		Car car1 = new Car("12345678");
		car1.getFasterCars().add(car1);
		
		ValidityReport report = validator.validate(ontology, car1);
		System.out.println(report.isValid()); // prints "false"
		
		Car car2 = new Car("22345678");
		Car car3 = new Car("32345678");
		car2.getFasterCars().add(car3);
		car2.getSlowerCars().add(car3);
		
		report = validator.validate(ontology, car2, car3);
		System.out.println(report.isValid()); // prints "false"
		
		Car car4 = new Car("42345678");
		Car car5 = new Car("52345678");
		car4.getFasterCars().add(car5);
		
		report = validator.validateAndInfer(ontology, car4, car5);
		System.out.println(report.isValid()); // prints "true"
		System.out.println(car5.getSlowerCars().size() == 1 &&
				car5.getSlowerCars().get(0) == car4); // prints "true"
	}
}
